import { createStore, combineReducers } from 'redux'

// //主reducer
// const initState = {}
// const reducer = (state = initState, action) => {
//   return {//第一次打开默认是undefine，之后就有值了
//     a: reducerA(state.a, action),
//     b: reducerB(state.b, action)
//   }
// }

// reducerA
const initStateA = {name: '张三'}
const reducerA = (state=initStateA, action) => {
  if (action.type === 'A/CHANGE_ANEM') {
    return{
      ...state,
      name: action.name
    }
  }
  return state
}

// reducerB
const initStateB = {name: '李四'}
const reducerB = (state=initStateB, action) => {
  if(action.type === 'B/CHANGE_ANEM') {
    return {
      ...state,
      name: action.name
    }
  }
  return state
}

const store = createStore(combineReducers({
  a: reducerA,
  b: reducerB
}), window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())

export default store